<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>对象的使用</title>
</head>
<body>
    <script>
        let user = {
            username: 'NingChe',
            password: '123456',
            'first-name': 'Gong',
            play: function(){
                console.log("Play");
            }
        }

        console.log(user);
        console.log(user.username);
        // 字符串属性的获取
        console.log(user['first-name']);

        // 修改属性
        user.password = '123456789'

        // 增加属性
        user.email = '2667596697@qq.com'
        console.log(user);

        // 删除属性
        delete user.email
        console.log(user)

        // 方法调用
        user.play()

        // 遍历对象
        for (const key in user) {
            console.log(key)
            // 遍历对象只能用 [key] 遍历，因为key为字符串
            console.log(user[key]);
        }
    </script>
</body>
</html>